<template>
	<view class="Login-page">
		<image mode="aspectFill" src="https://diancan-1252107261.cos.accelerate.myqcloud.com/yiliao/denglu-yemian.jpg">
		</image>
		<button @click="submit">授权登陆</button>
	</view>
</template>

<script>
	import {
		wxlogin
	} from "../../utils/API/login";

	export default {
		data() {
			return {
				obj: {
					appid: 'wxd435bac942345186',
					secret: 'ee3ecabb4c29378a8400a7fc1778393c',
					nickName: '',
					avatarUrl: '',
					code: ''
				}
			};
		},
		methods: {
			async submit() {
				// 获取用户信息
				await wx.getUserProfile({
					desc: '获取用户信息',
					success: (res) => {
						// console.log(res, 1)
						this.obj.nickName = res.userInfo.nickName;
						this.obj.avatarUrl = res.userInfo.avatarUrl;
						//  已登录呀
						wx.login({
							success: (code) => {
								this.obj.code = code.code
							}
						})
					}
				})
				let data = await wxlogin(this.obj)
				if (data.msg === "SUCCESS") {
					console.log(data.msg)
					wx.setStorageSync('wxuser', data.data)
					setTimeout(item => {
						wx.navigateBack({
							delta: 1
						})
					}, 1000)

				}
			}
		}
	}
</script>
<style>
	.Login-page {
		position: relative;
		height: 100vh;
		overflow: hidden;
	}

	.Login-page image {
		width: 100%;
		height: 100%;
	}

	.Login-page button {
		position: absolute;
		left: 50%;
		transform: translate(-50%, -50%);
		bottom: 30%;
		background-color: #2c76ef;
		color: #ffffff;
		padding: 0 100rpx;
		font-size: 35rpx;
	}
</style>
